package com.jml.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.jml.bean.Depart;
import com.jml.service.DepartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//提供者Controller，对外提供接口
@RequestMapping("/provider/depart")
@RestController
public class DepartController {
    @Autowired
    private DepartService departServiceImpl;

    //方法加一个注解
    @SentinelResource(value = "qpsFlowRule",blockHandler = "aaa")
    @GetMapping("/slow/get/{id}")
    public Depart getSlowHandle(@PathVariable("id") int id) {
        return departServiceImpl.getDepartById(id);
    }

    public Depart aaa(int id ,BlockException ex){
        Depart depart = new Depart(1,"");
        depart.setName("no any more~");
        return depart;
    }

    @GetMapping("/flow/get/{id}")
    public Depart getFLowHandle(@PathVariable("id") int id) {
        return null;
    }


    //根据id查询
    @GetMapping("/get/{id}")
    public Depart getHandle(@PathVariable("id") int id) {
        return departServiceImpl.getDepartById(id);
    }


    //查询列表
    @GetMapping("/list")
    public List<Depart> listHandle() {
        int i=0;
        int a = 1/i;
        return departServiceImpl.listAllDeparts();
    }



}
